package com.lb.jwitter.action.assessment;


import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;

import com.lb.jwitter.Tbl_TaiKhoan;
import com.lb.jwitter.hibernate.CommonDAO;
import com.lb.utils.orm.hibernate.Message;
import com.opensymphony.xwork2.Action;


@ContextConfiguration(locations="classpath:beans.xml")
public class AssessmentLectureSearchAction
{

	private List<Map<String, Object>> listLecture;

	public List<Map<String, Object>> getListLecture() {
		return listLecture;
	}

	public void setListLecture(List<Map<String, Object>> listLecture) {
		this.listLecture = listLecture;
	}
	///////////////////////////////////
	private Message msg;
	
	public Message getMsg() {
		return msg;
	}

	public void setMsg(Message msg) {
		this.msg = msg;
	}
	private String semesterId;
	public String getSemesterId() {
		return semesterId;
	}

	public void setSemesterId(String semesterId) {
		this.semesterId = semesterId;
	}

	private String subjectId;
	public String getSubjectId() {
		return subjectId;
	}

	public void setSubjectId(String subjectId) {
		this.subjectId = subjectId;
	}

	private String programId;
	public String getProgramId() {
		return programId;
	}

	public void setProgramId(String programId) {
		this.programId = programId;
	}
	/////////////////////////////////////
	private Tbl_TaiKhoan taiKhoanDangNhap;


	////////////////////////////////////

	public Tbl_TaiKhoan getTaiKhoanDangNhap() {
		return taiKhoanDangNhap;
	}

	public void setTaiKhoanDangNhap(Tbl_TaiKhoan taiKhoanDangNhap) {
		this.taiKhoanDangNhap = taiKhoanDangNhap;
	}


	@Autowired
	@Qualifier("commonDAO")
	private CommonDAO commonDao;
	
	public String execute() throws Exception
	{
		try {

			String courseId = subjectId + "_" + semesterId + "_" + programId;

			String query = "SELECT DISTINCT employee.Emp_ID as Emp_ID, employee.Emp_Name as Emp_Name	"
					+ "FROM thesisproject_dbo.employee "
					+ "JOIN  thesisproject_dbo.teaching "
					+ "ON (employee.Emp_ID = teaching.idEmp)	"
					+ "WHERE teaching.idCourse = '" + courseId + "' ";

			listLecture = commonDao.query_SQL_WithParams_AliasTransformer(
					query, null, 0, 0);

			return Action.SUCCESS;

	     }
	        catch(Exception e){
	        	e.printStackTrace();
	            msg.setPreMessage_b(false);
	            msg.setPreMessage_s("Error ");
	            return Action.ERROR;
	      }
	}	
}
